<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猜数字</title>
</head>
<body>
    <button id="reset">重新开始一局游戏</button><br/>
    请输入要猜的数字:  <input type="text" name="guestNum" id="guestNum"> <button id="guest">猜</button><br>
    已经猜的次数: <span id="count"></span> <br>
    结果: <span id="result"></span>

    <script src="js/jquery.min.js"></script>
    <script>
        //生成随机数
        let num =  Math.floor(Math.random()*100)+1;   //1-100
        console.log(num);
        let count = 0;
       
        $("#guest").click(function(){
            let guestNumber = $("#guestNum").val();
            count++;
            $("#count").text(count);

            if(num<guestNumber){
                //猜大了
                $("#result").text("猜大了");
                $("#result").css("color", "red");
            }else if(num>guestNumber){
                //猜小了
                $("#result").text("猜小了");
                $("#result").css("color", "red");
            }else{
                //猜对了
                $("#result").text("猜对了");
                $("#result").css("color", "green");
            }
        });

        $("#reset").click(function(){
            num =  Math.floor(Math.random()*100)+1;
            console.log(num);
            count = 0;
            $("#guestNum").val("");
            $("#count").text(count);
            $("#result").text("");
        });
    </script>
</body>
</html>